******************************************************************
** title:	Replication files for: 								**
**     Do Sexual Minorities Participate More in Politics? 		**
** date:	June 2024       							     	**
** authors: Daoust, Çakir, Dassonneville & Guévremont			**
******************************************************************

*Use the clean, pooled dataset
use "/Users/daoj2702/Desktop/Replication files/pooled_cdem_19-22.dta", clear

*Set Scheme
set scheme plotplain

*Encode elecid
encode elecid, gen(election_fe)


*********************
****   INDEX ********
*********************

*Summary of the name of the variables and items' wording

/*
member = Member of a provincial or federal political party
meeting = Attended a political meeting or speech
protest = Attended a rally or participated in a protest or demonstration
boycott = Boycotted or bought products for ethical, environmental, or political reasons
petition = Signed a petition in person or online
socialm = Followed any elected officials or candidates for office on social media
volunteer = Volunteered for a political party or candidate
contactRep = Contacted an elected representative (federal, provincial or local/municipal) 
donate = Donated money to a political candidate or party
circulatedInfo = Circulated, (re)posted or commented on political information, news or content online or offline
usedSocialm = Used social media to discuss politics or political issues
*/
 
*Generate the index 
gen index_institution=meeting+socialm+volunteer+contactRep+donate+member
replace index_institution=index_institution/6

alpha meeting socialm volunteer contactRep donate member

gen index_non_institution=protest+boycott+petition+circulatedInfo+usedSocialm
replace index_non_institution=index_non_institution/5

alpha protest boycott petition circulatedInfo usedSocialm 

*Set globals
global controls "i.gender_dicho i.age_cat eco_well_being i.education i.rural_urban i.franco i.election_fe"

*Generate the subsample
eststo index_institution: reg index_institution ///
								i.sexuality  $controls [pweight=pes_weights]
gen subsample=1 if e(sample)


reg index_institution i.sexuality $controls index_non_institution [pweight=pes_weights]
gen subsample2=1 if e(sample)


***********************************
****    FIGURES AND TABLES ********
***********************************

************************
****  	Table 1 ********
************************

tab sexuality if subsample2==1 [aweight=pes_weights]


*************************
****  	Figure 1 ********
*************************

hist index_institution if subsample2==1, percent ylabel(0(10)40) ///
	xtitle ("Institutionalized participation index")
graph save fig1_3.gph, replace 

hist index_non_institution if subsample2==1, percent ylabel(0(10)40) ///
	xtitle ("Non-institutionalized participation index")
graph save fig1_4.gph, replace 

graph combine fig1_3.gph fig1_4.gph 


*************************
****  	Figure 2 ********
*************************

*The institutionalized index
eststo index_institution_sub: reg index_institution ///
						  i.sexuality  $controls [pweight=pes_weights] if subsample2==1
est store m9
	
*The non-institutionalized index
eststo index_non_institution_sub: reg index_non_institution ///
							  i.sexuality $controls [pweight=pes_weights] if subsample2==1
est store m10
								

coefplot index_institution_sub index_non_institution_sub, ///
				keep(1.sexuality 2.sexuality 3.sexuality)  ///
				grid(between glcolor(black) glpattern(dash)) ///
				xtitle("Coefficients (reference category = heterosexual)") ///
				legend(position(6) row(1) order(2 "Institutionalized participation" 4 "Non-institutionalized participation"))

graph save subsample_eco.gph, replace


*Regression output
esttab m9 m10 using "tableA_D1.rtf", label nogap ///
	se(3) nonumbers replace noomitted nobase drop (*election_fe*)		
		

				
*************************
****  	Figure 3 ********
*************************	

*The institutionalized index
eststo index_institution_het: reg index_institution ///
						  i.sexuality  $controls [pweight=pes_weights] if subsample2==1
margins, at(sexuality=(0 1 2 3)) post						
est store m11
	
*The non-institutionalized index
eststo index_non_institution_het: reg index_non_institution ///
							  i.sexuality $controls [pweight=pes_weights] if subsample2==1
margins, at(sexuality=(0 1 2 3)) post
est store m12
																
coefplot m11 m12, ///
    title("") ///
    grid(between glcolor(black) glpattern(dash)) /// 
    xtitle("") xlabel(0.1(0.05)0.45) ///
    ylabel(1 "Heterosexual" 2 "Gay/Lesbian" 3 "Bisexual" 4 "Other") ///
    legend(position(6) row(1) order(2 "Institutionalized participation" 4 "Non-institutionalized participation"))

	
	
*************************
****  	Figure 4 ********
*************************			

*The institutionalized index
eststo gender_institution_7: reg index_institution ///
								i.sexuality##i.gender_dicho $controls [pweight=pes_weights] if subsample2==1
margins, dydx(sexuality) at(gender_dicho=(0)) post 
est store margins7

reg index_institution i.sexuality##i.gender_dicho $controls [pweight=pes_weights] if subsample2==1
margins, dydx(sexuality) at(gender_dicho=(1)) post 
est store margins8

coefplot margins7 margins8, ///
    title("Institutionalized political participation", box bexpand) ///
    grid(between glcolor(black) glpattern(dash)) /// 
    xtitle("AME (reference category = heterosexual)") xlabel(-0.05(0.05)0.25) ///
    xline(0) ylabel(1 "Gay/Lesbian" 2 "Bisexual" 3 "Other") ///
    legend(position(6) row(1) order(2 "Woman" 4 "Man"))

graph save fig_gender7.gph, replace
	
	
*The non-institutionalized index
eststo gender_institution_8: reg index_non_institution ///
								i.sexuality##i.gender_dicho $controls [pweight=pes_weights] if subsample2==1
margins, dydx(sexuality) at(gender_dicho=(0)) post 
est store margins9

reg index_non_institution i.sexuality##i.gender_dicho $controls [pweight=pes_weights] if subsample2==1
margins, dydx(sexuality) at(gender_dicho=(1)) post 
est store margins10

coefplot margins9 margins10, ///
	title ("Non-institutionalized political participation", box bexpand) ///
	grid(between glcolor(black) glpattern(dash)) ///
	xtitle("AME (reference category = heterosexual)") xlabel(-0.05(0.05)0.25) ///
	xline(0) ylabel(1 "Gay/Lesbian" 2 "Bisexual" 3 "Other") ///
	legend(position(6) row(1) order(2 "Woman" 4 "Man"))

graph save fig_gender8.gph, replace	
	
grc1leg fig_gender7.gph fig_gender8.gph, legendfrom(fig_gender7.gph) 
 
 
*Regression output 
esttab gender_institution_7 gender_institution_8 using "tableA_D2.rtf", label nogap ///
	se(3) nonumbers replace noomitted nobase drop (*election_fe*)


			
*********************************
**** 	ONLINE APPENDIX  ********
*********************************	
		
*************
*Descriptive*
****Stats****
*************

*Table A1
tab election_fe if subsample2==1 [aweight=pes_weights]

*Table A2
eststo clear
estpost sum age_cat gender_dicho sexuality education eco_well_being franco ///
		rural_urban meeting protest boycott petition socialm volunteer contactRep ///
		donate circulatedInfo usedSocialm member ///
		index_institution index_non_institution if subsample2==1
esttab using "Descriptives_stat_informal_subsample.rtf", cells("min max mean(fmt(3)) sd(fmt(3)) count") label mlabels(,titles) replace
 
 
************
*Figure E1**
************
*Dichotomous index
gen index_institution_dicho = meeting_dicho+socialm_dicho+volunteer_dicho+contactRep_dicho+donate_dicho+member
replace index_institution_dicho = index_institution_dicho/6

gen index_non_institution_dicho = protest_dicho+boycott_dicho+petition_dicho+circulatedInfo_dicho+usedSocialm_dicho
replace index_non_institution_dicho = index_non_institution_dicho/5

*The institutionalized index (dicho)
eststo index_institution_dicho: reg index_institution_dicho ///
								i.sexuality  $controls if subsample2==1 [pweight=pes_weights]
	
*The non-institutionalized index (dicho)
eststo index_non_institution_dicho: reg index_non_institution_dicho ///
								i.sexuality $controls if subsample2==1 [pweight=pes_weights]

coefplot index_institution_dicho index_non_institution_dicho, ///
				keep(1.sexuality 2.sexuality 3.sexuality) title("") ///
				grid(between glcolor(black) glpattern(dash)) ///
				xtitle("Coefficients (reference category = heterosexual)") ///
				legend(position(6) row(1) order(2 "Institutionalized participation (dicho)" 4 "Non-institutionalized participation (dicho)"))
				
************
*Figure F1**
************				
*Compositionnal effect test

*The institutionalized index with/without SES as controls
eststo index1_nocontrols: reg index_institution ///
							i.sexuality if subsample2==1 [pweight=pes_weights]
eststo index1_withcontrols: reg index_institution ///
							i.sexuality $controls if subsample2==1 [pweight=pes_weights]
coefplot index1_nocontrols index1_withcontrols, ///
				keep(1.sexuality 2.sexuality 3.sexuality) title("") xlabel(0(0.05)0.2) ///
				grid(between glcolor(black) glpattern(dash)) ///
				xtitle("Coefficients institutionalized index" "(reference category = heterosexual)") ///
				legend(position(6) row(1) order(2 "Without control variables" 4 "With control variables"))
graph save rfigm3_1.gph, replace

*The non-institutionalized index with/without SES as controls
eststo index2_nocontrols: reg index_non_institution ///
							i.sexuality if subsample2==1 [pweight=pes_weights]
eststo index2_withcontrols: reg index_non_institution ///
							i.sexuality $controls if subsample2==1 [pweight=pes_weights]
coefplot index2_nocontrols index2_withcontrols, ///
				keep(1.sexuality 2.sexuality 3.sexuality) title("") xlabel(0(0.05)0.2) ///
				grid(between glcolor(black) glpattern(dash)) ///
				xtitle("Coefficients non-institutionalized index" "(reference category = heterosexual)") ///
				legend(position(6) row(1) order(2 "Without control variables" 4 "With control variables"))
graph save rfigm3_2.gph, replace

grc1leg rfigm3_1.gph rfigm3_2.gph, legendfrom(rfigm3_1.gph)


************
*Figure G1**
************
*Poisson regression		
		
*The institutionalized index
eststo index_institution_p: poisson index_institution ///
								i.sexuality $controls if subsample2==1 [pweight=pes_weights]

margins, dydx(i.sexuality) post
est store m5

*The non-institutionalized index
eststo index_non_institution_p: poisson index_non_institution ///
								i.sexuality $controls if subsample2==1 [pweight=pes_weights]
margins, dydx(i.sexuality) post
est store m6

coefplot m5 m6, ///
		title("") ///
		grid(between glcolor(black) glpattern(dash)) ///
		xtitle("AME (reference category = heterosexual)") ///
		legend(position(6) row(1) order(2 "Institutionalized participation" 4 "Non-institutionalized participation"))

 

************
*Figure H1**
************
*Moderation effect + predicted participation index

*The institutionalized index
eststo gender_institution_9: reg index_institution ///
								i.sexuality##i.gender_dicho $controls [pweight=pes_weights] if subsample2==1
margins, at(sexuality=(0 1 2 3) gender_dicho=(0)) post 
est store margins11

reg index_institution i.sexuality##i.gender_dicho $controls [pweight=pes_weights] if subsample2==1
margins, at(sexuality=(0 1 2 3) gender_dicho=(1)) post
est store margins12

coefplot margins11 margins12, ///
	title("Institutionalized political participation", box bexpand) ///
    grid(between glcolor(black) glpattern(dash)) /// 
    xtitle("") xlabel(0.1(0.05)0.45)  ///
    ylabel(1 "Heterosexual" 2 "Gay/Lesbian" 3 "Bisexual" 4 "Other") ///
    legend(position(6) row(1) order(2 "Woman" 4 "Man"))

graph save fig_gender9.gph, replace


*The non-institutionalized index
eststo gender_institution_10: reg index_non_institution ///
								i.sexuality##i.gender_dicho $controls [pweight=pes_weights] if subsample2==1
margins, at(sexuality=(0 1 2 3) gender_dicho=(0)) post 
est store margins13

reg index_non_institution i.sexuality##i.gender_dicho $controls [pweight=pes_weights] if subsample2==1
margins, at(sexuality=(0 1 2 3) gender_dicho=(1)) post
est store margins14

coefplot margins13 margins14, ///
	title("Non-institutionalized political participation", box bexpand) ///
    grid(between glcolor(black) glpattern(dash)) /// 
    xtitle("") xlabel(0.1(0.05)0.45) ///
    ylabel(1 "Heterosexual" 2 "Gay/Lesbian" 3 "Bisexual" 4 "Other") ///
    legend(position(6) row(1) order(2 "Woman" 4 "Man"))
	
graph save fig_gender10.gph, replace	
	
grc1leg fig_gender9.gph fig_gender10.gph, legendfrom(fig_gender10.gph)  
 
 
